def valid(x):
    x=int(x)
    for i in range(2,int(x**0.5)+1):
        if x%i==0 or x//i==0:
            return 0
    return 1
while True:
    a = int(input())
    a=str(a)
    b=[]
    for i in a:
        b.append(i)
    for r in range(1,len(a)):
        for i in range(r, len(a)):
            b.append(a[i-r:i])
    c=[int(x) for x in b if valid(x)]
    if valid(a):
        c.append(int(a))
    c.append(0)
    print(max(c))
